package org.javagril.yuetong.controller.scheduling;

import org.javagril.yuetong.bean.RespBean;
import org.javagril.yuetong.bean.RespPageBean;
import org.javagril.yuetong.bean.Scheduling;
import org.javagril.yuetong.service.CarriersService;
import org.javagril.yuetong.service.SchedulingService;
import org.javagril.yuetong.service.TruckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/scheduling")
public class SchedulingController {
    @Autowired
    SchedulingService schedulingService;
    @Autowired
    CarriersService carriersService;
    @Autowired
    TruckService truckService;
    /*查询所有 调度任务数据*/
    @GetMapping("/")
    public RespPageBean getSchedulingByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        return schedulingService.getSchedulingByPage(page, size);
    }

    /*查询未分配的信息*/
    @GetMapping("/carriers")
    public RespPageBean getCarriersByState(Integer state,Integer page,Integer size) {
        return carriersService.getCarriersByState(state, page, size);
    }

    /*获取车辆的
    信息*/
    @GetMapping("/truck")
    public RespPageBean getTruckByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, Integer state) {
        return truckService.getTruckByPageAndState(page, size,state);
    }


    /*车辆调度*/
    @PostMapping("/")
    public RespBean addSchedule(@RequestBody Scheduling scheduling) {
        if (schedulingService.addSchedule(scheduling)) {
            return RespBean.ok("车辆调度成功...o(*￣▽￣*)ブ");
        }
        return RespBean.error("车辆调度失败...￣へ￣");
    }
}
